# coding:utf8
import pandas as pd
from py2neo import *
import numpy as np
from pprint import pprint
graph = Graph("http://127.0.0.1:7474",username="neo4j",password="neo4j")
df = pd.read_excel('数据结构.xlsx')

import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")


if __name__ == "__main__":
    graph.run("match (n:data_structure_name)-[relat]-(m) delete n,relat,m")

    for i in range(len(df)):
        # 创建节点
        node_name = Node("data_structure_name", name=df.loc[i, 'name'])
        node_description = Node("data_structure_description", name=df.loc[i, 'description'])
        node_operation = Node("data_structure_operation", name=df.loc[i, "operation"])

        graph.create(node_name)
        graph.create(node_description)
        graph.create(node_operation)


        relations = []
        relations.append(Relationship(node_name, "描述", node_description))
        relations.append(Relationship(node_name, "操作", node_operation))

        for relation in relations:
            graph.create(relation)
        print('no')

    res = graph.run("match (n:data_structure_name) return n")
    for i in res.data():
        pprint((i['n']['name']))








